<%= render :partial => 'excursions/vish_viewer.full' %>

<script>
	options = {};
	var configuration = {};

	configuration["ImagesPath"] = "/assets/";
	configuration["StylesheetsPath"] = "/assets/";

	// Recommendations API
	configuration["recommendationsAPI"] = {
		rootURL: "<%=Vish::Application.config.full_domain%>" + "/excursions/last_slide.json"
	};

	//Quiz Sessions API (Audience Response System)
	configuration["ARS_API"] = {
		rootURL: '<%=QuizSession.root_url%>'
	};

	//WAPP TOKEN API
	configuration["WAPP_TOKEN_API"] = {
		rootURL: "<%=Vish::Application.config.full_domain%>" + "/apis/wapp_token"
	};

	//Tracking System
	<%if Vish::Application.config.trackingSystem %>
		configuration["TrackingSystemAPIKEY"] = "<%= Vish::Application.config.APP_CONFIG['trackingSystemAPIKEY'] %>";
		configuration["TrackingSystemAPIURL"] = "<%= Vish::Application.config.APP_CONFIG['trackingSystemAPIURL'] %>";
		<% unless params["trseid"].blank? %>
			options["TrackingSystemRelatedEntryId"] = "<%= params['trseid'] %>";
		<% end %>
	<%end%>

	//LOEP configuration
	<% unless Vish::Application.config.APP_CONFIG['loep'].nil? or @excursion.nil? or @excursion.activity_object.nil? %>
		<% loepConfig = Vish::Application.config.APP_CONFIG['loep'] %>
		<% tokenURL = Embed.checkUrlProtocol(Vish::Application.config.full_domain + '/loep/session_token.json', request.protocol) %>
		configuration["loepSettings"] = {
			tokenURL: '<%=tokenURL%>',
			domain: '<%=Embed.checkUrlProtocol(loepConfig["domain"], request.protocol)%>',
			app: '<%=loepConfig["app_name"]%>',
			loId: '<%=@excursion.activity_object.getGlobalId()%>',
			evmethod: "wblts"
		};
		<% unless loepConfig["repository_name"].blank? %>
			configuration["loepSettings"]["repository"] = '<%=loepConfig["repository_name"]%>';
		<% end %>
		<% if user_signed_in? %>
			configuration["loepSettings"]["user_id"] = '<%=current_user.id%>';
		<% end %>
	<%end%>

	options["configuration"] = configuration;
	options["developping"] = false;

	options["environment"] = {
		name: "<%= Vish::Application.config.name %>"
	}

	//User data
	<% if user_signed_in? %>
		options["user"] = {
			name: "<%= current_subject.name %>",
			id: "<%= Actor.normalize_id(current_subject) %>",
			token: "<%= form_authenticity_token %>"
		};
	<% end %>

	options["lang"] = "<%= I18n.locale.to_s%>";

	//Watermark
	<% if @excursion %>
		options["watermarkURL"] = "<%=excursion_path(@excursion)%>";
	<% end %>

	//FullScreen
	<% if @excursion %>
		options["fullScreenFallback"] = {
			enterFullscreenURL: "<%=excursion_path(@excursion, :format => :full)%>"
		};
		<% if @orgUrl %>
			options["fullScreenFallback"].exitFullscreenURL = "<%=@orgUrl%>";
		<% end %>
	<% end %>

	//comeBackUrl for Mobile Devices
	<% if @orgUrl %>
	  options["comeBackUrl"] = "<%=@orgUrl%>";
	<% else %>
	  <% if request && request.referrer %>
		options["comeBackUrl"] = "<%=request.referrer%>";
	  <% end %>
	<% end %>

	<% unless params["oreferrer"].blank? %>
		options["referrer"] = "<%=params['oreferrer']%>";
	<% end %>

	<% if @quiz_session %>
		options["quizSessionId"] = "<%= @quiz_session.id %>";
	<% end %>
	
	//Extra options from parent
	try {
		if(typeof window.parent.options != "undefined"){
			options["readHashFromParent"] = window.parent.options["readHashFromParent"];
		}
	} catch(err){}


	options.addons = [];

	var addon = new Object();
	addon.target = "Both";
	addon.id = "IframeMessenger";
	addon.url = "";
	addon.config = {enable: true};
	options.addons.push(addon);


	function start(){
		var isPreview = false;
		try {
			isPreview = window.parent.VISH && 
						window.parent.VISH.Editor && 
						(typeof window.parent.VISH.Editor.Preview.getPreview == "function") && 
						(typeof window.parent.VISH.Editor.Preview.getPreview() != 'undefined') &&
						(window.parent.VISH.Editor.Preview.getPreview() != null);
		} catch(exception) {
			isPreview = false;
		}
		
		var myexcursion;

		if(isPreview){
			options["preview"] = true;
			myexcursion =  window.parent.VISH.Editor.Preview.getPreview();
		} else {
			<% if @excursion %>
				myexcursion = <%= raw @excursion.json %>;
		  	<% elsif @quiz_session %>
				myexcursion = <%= raw @quiz_session.quizJSON %>;
			<% else %>
				myexcursion = null;
			<% end %>
		}
			
		VISH.Viewer.init(options , myexcursion);
	}
</script>